package com.example.gulimall.coupon.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.example.common.entity.coupon.SeckillSessionEntity;
import com.example.gulimall.coupon.service.SeckillSessionService;
import com.example.common.utils.PageUtils;
import com.example.common.utils.R;



/**
 * 秒杀活动场次
 *
 * @author zyred
 * @email zyred@163.com
 * @date 2021-08-23 10:34:05
 */
@RestController
@RequestMapping("coupon/seckillsession")
public class SeckillSessionController {


    @Autowired
    private SeckillSessionService seckillSessionService;

    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = seckillSessionService.queryPage(params);
        return R.ok().put("page", page);
    }


    @GetMapping("/uploadSecKillSkuLatest/{day}")
    public List<SeckillSessionEntity> uploadSecKillSkuLatest3Day(@PathVariable("day") int day) {
        return this.seckillSessionService.uploadSecKillSkuLatestConditionDay(day);
    }


    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Long id){
		SeckillSessionEntity seckillSession = seckillSessionService.getById(id);
        return R.ok().put("seckillSession", seckillSession);
    }

    @RequestMapping("/save")
    public R save(@RequestBody SeckillSessionEntity seckillSession){
		seckillSessionService.save(seckillSession);
        return R.ok();
    }

    @RequestMapping("/update")
    public R update(@RequestBody SeckillSessionEntity seckillSession){
		seckillSessionService.updateById(seckillSession);
        return R.ok();
    }

    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] ids){
		seckillSessionService.removeByIds(Arrays.asList(ids));
        return R.ok();
    }

}
